package com.itheima.excel.model;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.itheima.pojo.Student;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
public class StudentModel {
    @ExcelProperty("姓名")
    private String name;

    @ExcelProperty("学号")
    private String no;

    @ExcelProperty("性别")
    private String genderStr;

    @ExcelProperty("手机号")
    private String phone;

    @ExcelProperty("身份证号")
    private String idCard;

    @ExcelProperty("是否来自院校")
    private String isCollegeStr;

    @ExcelProperty("居住地址")
    private String address;

    @ExcelProperty("学历")
    private String degreeStr;

    @ExcelProperty("毕业时间")
    private LocalDate graduationDate;

    @ExcelProperty("班级")
    private String clazzName;

    public Student toStudent(Integer clazzId) {
        Student student = BeanUtil.copyProperties(this, Student.class);
        student.setGender("男".equals(this.getGenderStr()) ? 1 : 2);
        student.setIsCollege("是".equals(this.getIsCollegeStr()) ? 1 : 0);
        switch (this.getDegreeStr()) {
            case "初中" -> student.setDegree(1);
            case "高中" -> student.setDegree(2);
            case "大专" -> student.setDegree(3);
            case "本科" -> student.setDegree(4);
            case "硕士" -> student.setDegree(5);
            case "博士" -> student.setDegree(6);
        }
        student.setClazzId(clazzId);
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(student.getCreateTime());
        return student;
    }
}
